package de.breitbeil.jbooking.ui.form;

import javax.swing.JComponent;
import javax.swing.JTextField;

import org.springframework.richclient.form.AbstractForm;
import org.springframework.richclient.form.builder.TableFormBuilder;

import de.breitbeil.jbooking.domain.Person;

public class PersonForm extends AbstractForm {

    private JComponent firstNameField;
    
    public PersonForm(Person person) {
        super(person);
        setId("personForm");
    }
    
    @Override
    protected JComponent createFormControl() {
        TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
        formBuilder.setLabelAttributes("colGrId=label colSpec=right:pref");

        formBuilder.addSeparator(getMessage(getId()) + ".generalSeparator.label");
        formBuilder.row();

        formBuilder.add("address0");
        formBuilder.add("address");
        formBuilder.row();
   
        firstNameField = formBuilder.add("firstname")[1]; 
        formBuilder.add("lastname");
        formBuilder.row();
        formBuilder.add("email", "colSpan=1");
        formBuilder.add("mobil");
        formBuilder.row();
        formBuilder.add("homePhone");
        formBuilder.add("workPhone");
        formBuilder.row();
        formBuilder.add("birthday", "align=left");
        formBuilder.row();

        formBuilder.addSeparator(getMessage(getId()) + ".partnerSeparator.label");
        formBuilder.row();
        formBuilder.add("p_firstname");
        formBuilder.add("p_lastname");
        formBuilder.row();
        formBuilder.add("p_birthday", "align=left");
        formBuilder.row();
        
        formBuilder.addSeparator(getMessage(getId()) + ".addressSeparator.label");
        formBuilder.row();
        formBuilder.add("address1");
        formBuilder.row();
        formBuilder.add("address2");
        formBuilder.row();
        formBuilder.add("address3");
        formBuilder.row();
        // We want to make the zip code UI field smaller than the default. The add method
        // returns an array of two components, the field label and the component bound to
        // the property.
        JComponent zipField = formBuilder.add("zip", "colSpan=1 align=left")[1];
        ((JTextField) zipField).setColumns(8);
        formBuilder.add("city", "colSpan=1 align=left");
        formBuilder.row();
        
        formBuilder.addSeparator(getMessage(getId()) + ".commentSeparator.label");
        formBuilder.row();
        formBuilder.addTextArea("description");
        formBuilder.row();

        return formBuilder.getForm();
    }

    /* geht nicht
     * Try to place the focus in the firstNameField whenever the initial focus is being set.
     * @return
     
    public boolean requestFocusInWindow() {
        return firstNameField.requestFocusInWindow();
    }
    */
}
